﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;


namespace MyVocationSpace
{
    public partial class MyProfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
            if (Session["UserID"] != null)
            {
                if (Request.QueryString["IDUser"] != null)
                {
                    int IdUser = Convert.ToInt32(Request.QueryString["IDUser"]);
                    GetData(IdUser);
                    lnlEdit.Visible = false;
                }
                else
                {
                    GetData(Convert.ToInt32(Session["UserID"]));
                    lnlEdit.Visible = true;

                }
                if (!IsPostBack)
                {
                    if (Request.QueryString["Updated"] == "1")
                    {
                        //GetData(Convert.ToInt32(Session["UserID"]));
                        lnlEdit.Visible = true;
                        divUpdateMsg.Style.Add("display", "block");
                        spanUpdateMsg.InnerHtml = "The information has been successfully updated.";
                    }
                }
            }
            else
            {
                Response.Redirect("Home.aspx");
            }

        }

        public void GetData(int Iduser)
        {
            ViewState["Iduser"] = Iduser;
            string[] Detail = BAL.Users.GetUserDetails(Iduser);
            username.InnerHtml = Detail[1] + " " + Detail[2];
            Occu.InnerHtml = Detail[0];
            city.InnerHtml = Detail[7];
            country.InnerHtml = Detail[16];
            industry.InnerHtml = Detail[18];
            education.InnerHtml = Detail[20];
            current.InnerHtml = Detail[0];
            org.InnerHtml = Detail[14];
            industryMain.InnerHtml = Detail[18];
            string img = Detail[19];
            if (img != "")
            {
                idImg.Src = "UsersPhoto/" + img;
            }
            else
            {
                idImg.Src = "UsersPhoto/icon_no_photo_60x60.png";
            }

            int count = BAL.Users.GetConnectionByUser(Iduser);
            connect.Text = count.ToString() + " " + "<font style=\"color:#1C6F93; font-size:12px; font-weight:normal;\">connections</font>";

            //connection.Style.Add("href", "Connections.aspx?IDUser= " + Iduser + "");
           

            DataSet ds = BAL.Users.GetVocationByUser(Iduser);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //phVocation.Controls.Add(new LiteralControl("<table width=\"350px\">"));
                    //    foreach(DataRow dr in ds.Tables[0].Rows)
                    //    {
                    //        phVocation.Controls.Add(new LiteralControl("<tr><td align=\"left\">" + dr["VocationName"] + "</td></tr>"));
                    //    }
                    //phVocation.Controls.Add(new LiteralControl("</table>"));

                    phVocation.Controls.Add(new LiteralControl("<ul width=\"350px\" style=\"margin-top:-0px; margin-left:-22px\">"));
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        phVocation.Controls.Add(new LiteralControl("<li align=\"left\">" + dr["VocationName"] + "</li>"));
                    }
                    phVocation.Controls.Add(new LiteralControl("</ul>"));
                }
            }

        }

        protected void connect_Click(object sender, EventArgs e)
        {
            //connect.Style.Add("href", "Connections.aspx?IDUser= " + Convert.ToInt32( ViewState["Iduser"]) + "");
            Response.Redirect("Connections.aspx?IDUser= " + Convert.ToInt32(ViewState["Iduser"]) + "");
        }
    }
}